﻿Public Class SqlDiff 

    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Init()
    End Sub

    Public Sub init()
        ' Dim Combo As ComboBoxEdit = New ComboBoxEdit
        Dim Coll As XtraEditors.Controls.ComboBoxItemCollection = ApexSqlScript.Properties.Items
        Coll.BeginUpdate()
        'IO.Path.Combine(DeskTopManager.ApplicationDataFolder, CommonExt.Utils.FileExt.EncodedFileName("DataFieldSecurity" + AppManager.UserName.ToLower))

        Try
            ' make a reference to a directory
            Dim di As New System.IO.DirectoryInfo("D:\VB\SCIEF\VS2010\DotNet3\SystemBoxExpress\SystemBOXExpress\DevTools")
            Dim diar1 As System.IO.FileInfo() = di.GetFiles("*.axd*")
            Dim dra As System.IO.FileInfo

            'list the names of all files in the specified directory
            For Each dra In diar1
                Coll.Add(dra)
            Next
        Finally
            Coll.EndUpdate()
        End Try
        ApexSqlScript.SelectedIndex = -1
        Controls.Add(ApexSqlScript)

        SourceBD.Text = AppManager.DbName
        SourceServer.Text = AppManager.DbServerName
        SourceUser.Text = "sql_ssis"
        SourcePassword.Text = "1x2x3x4X"

        DestBD.Text = AppManager.DbName
        DestServer.Text = AppManager.DbServerName
        DestUser.Text = "sql_ssis"
        DestPassword.Text = "1x2x3x4X"

    End Sub

    Public Shared Sub WorkWithFilesInDir(ByVal aDir As System.IO.DirectoryInfo)
        Dim aFile As System.IO.FileInfo
        For Each aFile In aDir.GetFiles()
            Console.WriteLine(aFile.FullName)
        Next
    End Sub

    Private Sub OKButton_Click(sender As System.Object, e As System.EventArgs) Handles OKButton.Click
        If Len(SourceBD.Text) > 0 AndAlso _
            Len(SourcePassword.Text) > 0 AndAlso _
            Len(SourceServer.Text) > 0 AndAlso _
            Len(SourceUser.Text) > 0 AndAlso _
            Len(DestBD.Text) > 0 AndAlso
            Len(DestPassword.Text) > 0 AndAlso _
            Len(DestServer.Text) > 0 AndAlso _
            Len(DestUser.Text) > 0 Then

            If ApexSqlScript.SelectedText.Contains("axdd") Then
                'C:\Progra~2\ApexSQL\ApexSQLDataDiff2010\apexsqldatadiff /project:D:\Backup\SQLDIFF\PROJECT\SystemBox_Master_META.axdd /server1:s-corp-sql\sqlcorp2005 /database1:SystemBox_Master /user1:sql_ssis /password1:1x2x3x4X /server2:s-corp-sql\sqlcorp2005 /database2:SystemBox_Master_PREVIOUS /user2:sql_ssis /password2:1x2x3x4X /output_type:tsql /output_file:D:\Backup\SQLDIFF\SCRIPT\%All%_METADATA.sql /v /encoding:u8 
                Process.Start("C:\Progra~2\ApexSQL\ApexSQLDataDiff2008\apexsqldatadiff", " /project:" + "D:\VB\SCIEF\VS2010\DotNet3\SystemBoxExpress\SystemBOXExpress\DevTools\" + ApexSqlScript.SelectedText.ToString + " /server1:" + SourceServer.Text + " /database1:" + SourceBD.Text + " /user1:" + SourceUser.Text + " /password1:" + SourcePassword.Text + " /server2:" + DestServer.Text + " /database2:" + DestBD.Text + " /user2:" + DestUser.Text + " /password2:" + DestPassword.Text + " /output_type:tsql /output_file:" + SavedFileName.Text + " /v /encoding:u8 /f")
            End If
            If ApexSqlScript.SelectedText.Contains("axds") Then
                'C:\Progra~2\ApexSQL\ApexSQLDiff2011\apexsqldiff /project:D:\Backup\SQLDIFF\PROJECT\CompareMaster_SP.axds /server1:s-corp-sql\sqlcorp2005 /database1:SystemBox_Master /user1:sql_ssis /password1:1x2x3x4X /server2:s-corp-sql\sqlcorp2005 /database2:SystemBox_Master_PREVIOUS /user2:sql_ssis /password2:1x2x3x4X /output_type:tsql /output_file:D:\Backup\SQLDIFF\SCRIPT\%All%_SP.sql /v /encoding:u8 /nscu
                Process.Start("C:\Progra~2\ApexSQL\ApexSQLDiff2008\apexsqldiff", " /project:" + "D:\VB\SCIEF\VS2010\DotNet3\SystemBoxExpress\SystemBOXExpress\DevTools\" + ApexSqlScript.SelectedText.ToString + " /server1:" + SourceServer.Text + " /database1:" + SourceBD.Text + " /user1:" + SourceUser.Text + " /password1:" + SourcePassword.Text + " /server2:" + DestServer.Text + " /database2:" + DestBD.Text + " /user2:" + DestUser.Text + " /password2:" + DestPassword.Text + " /output_type:tsql /output_file:" + SavedFileName.Text + " /v /encoding:u8 /nscu /f")
            End If

        Else
            MessageWindow.ShowMessage("You need to enter all value...", MsgBoxStyle.Information)
        End If
    End Sub

    Private Sub ApexSqlScript_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ApexSqlScript.SelectedIndexChanged
        ' + " " + DateTime.Now().ToString
        SavedFileName.Text = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), ApexSqlScript.Text.Substring(0, ApexSqlScript.Text.IndexOf(".")) + ".sql")
    End Sub
End Class